package com.smartticket.jeju.repository;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.smartticket.jeju.model.User;

@Repository
public class UserRepositoryImplByIbatis implements UserRepository 
{
	@Autowired
	private SqlMapClient sqlMapClient;

	public void insert(User user) 
	{
		try 
		{
			this.sqlMapClient.update("User.insertUser", user);
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}

	public List<User> findAll() 
	{
		try 
		{
			return (List<User>)sqlMapClient.queryForList("User.selectUser");
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
			return null;
		}
	}

	public boolean isUser(String id, String pw) 
	{
		Map<String, String> param = new HashMap<String, String>();
		param.put("id", id);
		try
		{
			User user = (User)sqlMapClient.queryForObject("User.selectUser");
			
			if(pw.equals(user.getPw()))
				return true;
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		return false;
	}
}
